package com.tamtamy.jtta.data.json;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.tamtamy.jtta.data.NetworkList;
import com.tamtamy.jtta.exception.NoResultException;

public class JSONNetworkList extends NetworkList {
	
	private static final long serialVersionUID = 6666281234154552681L;

	public JSONNetworkList(JSONObject jsonObject) throws NoResultException{
		super();
		JSONArray networkListJSON = (JSONArray)jsonObject.get("list");
		if (networkListJSON == null || networkListJSON.size()==0){
			throw new NoResultException("No comments found");
		}
		for (int i = 0; i < networkListJSON.size(); i++) {
			JSONObject networkJSON = networkListJSON.getJSONObject(i);
			this.add(new JSONNetworkDetails(networkJSON));
		}	
		JSONObject paginationInfo = (JSONObject)jsonObject.get("paginationInfo");
		int total = paginationInfo.getInt("total");
		setTotal(total);
	}
}
